Page({
    data: {


      params: {
        id: '',
        pageNum: 1,
        pageSize: 999999,
        isSold: true
      },

      list: [],
      type: 1,
      total: 0
    },
    // 头部切换
  clickTab (e) {
    console.log(e)

    var type = e.currentTarget.dataset.type
    var isSold = "params.isSold"
    this.setData({
      type: type,
      [isSold]: type == 1 ? true: false
    })

    this.setData({
      list: []
    })

    this.getList(this.data.params)
  },


  getList (params) {
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/bookinfo/user/sold/list/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {
          _this.setData({
            total: res.data.data.totalCount
          })
          var arr = _this.data.list
          if (res.data.data.resultList!='') {
            res.data.data.resultList.forEach(function (item,index) {
              arr.push(item)
            })
            _this.setData({
              list: arr
            })
          }
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },
  onLoad (options) {
    var id = "params.id"
    this.setData({
      [id]: options.bookId
    })

    this.getList(this.data.params)
  },
  onReachBottom() {
    console.log(1111111)
    if (this.data.list.length != this.data.total) {
      this.data.params.pageNum += 1
      this.getList(this.data.params)
    }
  }
})
